package neo4j;

import neo4j.util.Neo4jUtil;

import org.neo4j.graphdb.Direction;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.RelationshipType;
import org.neo4j.graphdb.Transaction;

public class HelloWorld
{
	private static enum RelTypes implements RelationshipType
	{
		KNOWS
	}

	public static String DB_PATH = "C:/dev/neo4j-community-1.8.2/data/graph.db";

	public static void main(String[] args)
	{
		GraphDatabaseService graphDbService = Neo4jUtil.startService(DB_PATH);
		Node firstNode, secondNode;
		Relationship relationship;

		Transaction tx = graphDbService.beginTx();
		try
		{
			firstNode = graphDbService.createNode();
			firstNode.setProperty("message", "Hello, ");
			secondNode = graphDbService.createNode();
			secondNode.setProperty("message", "World!");

			relationship = firstNode.createRelationshipTo(secondNode, RelTypes.KNOWS);
			relationship.setProperty("message", "brave Neo4j ");
			tx.success();

			System.out.print(firstNode.getProperty("message"));
			System.out.print(relationship.getProperty("message"));
			System.out.print(secondNode.getProperty("message"));

			// let's remove the data
			firstNode.getSingleRelationship(RelTypes.KNOWS, Direction.OUTGOING).delete();
			firstNode.delete();
			secondNode.delete();
		}
		finally
		{
			tx.finish();
			graphDbService.shutdown();
		}

	}

}
